define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'wages/index',
        export_url: 'wages/export',
        restore_url: 'wages/restore',
        generate_url: 'wages/generate',
        generateOne_url: 'wages/generateOne'
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh','export',
                    [{
                        text: '批量工资结算',
                        url: init.generate_url,
                        method: 'open',
                        auth: 'generate',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        extend: 'data-width="700px" data-height="600px"',
                    }],
                ],
                cols: [[
                    {field: 'uid', title: 'ID', hide: true, search: false, width: 100},
                    {field: 'job_number', title: '工号', search: false},
                    {field: 'true_name', title: '员工姓名'},
                    {field: 'base_salary', title: '基本工资'},
                    {field: 'ratio_amount', title: '项目提成', search: false},
                    {field: 'bonus_amount', title: '奖金', search: false},
                    {field: 'all_amount', title: '实发金额', search: false},
                    {field: 'wage_time', title: '结算时间', search: 'range'},
                    {
                        width: 120,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '工资结算',
                                url: init.generateOne_url,
                                method: 'open',
                                auth: 'generateOne',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                field: 'uid',
                                extend: 'data-width="700px" data-height="708px"',
                            }]
                        ]
                    }
                ]],
            });
            ea.listen();
        },
        index2: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'wages/index2',
                },
                toolbar: ['refresh'],
                cols: [[
                    {field: 'uid', title: 'ID', hide: true, search: false, width: 100},
                    {field: 'job_number', title: '工号', search: false},
                    {field: 'true_name', title: '姓名'},
                    {field: 'base_salary', title: '基本工资'},
                    {field: 'ratio_amount', title: '项目提成', search: false},
                    {field: 'bonus_amount', title: '奖金', search: false},
                    {field: 'all_amount', title: '实发金额', search: false},
                    {field: 'wage_time', title: '结算时间', search: 'range'},
                ]],
            });
            ea.listen();
        },
        generate: function () {
            ea.listen();
            // ea.listen(function (data) {
            //     return data;
            // }, function (res) {
            //     ea.msg.success(res.msg, function () {
            //         var index = parent.layer.getFrameIndex(window.name);
            //         parent.layer.close(index);
            //         parent.$('[data-table-refresh]').trigger("click");
            //         parent.$('[data-table-export]').trigger("click");
            //     });
            // });
        },
        generateOne: function () {
            ea.listen();
        }
    };
    return Controller;
});